package pe.gob.reniec.cel.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @author Lennon Shimokawa [http://lshimokawa.net]
 */
@Component
@Aspect
public class LoggingAspect {

    private Logger logger = Logger.getLogger(LoggingAspect.class);

    @Around("pe.gob.reniec.cel.aop.SystemArchitecture.servicePointcut()")
    public Object aroundService(ProceedingJoinPoint pjp)
            throws Throwable {
        logger.debug("Interceptado aroundService antes del joinpoint");
        Object[] args = pjp.getArgs();
        Object retVal = pjp.proceed(args);
        logger.debug("Interceptado aroundService despues del joinpoint");
        logger.debug("retVal = " + retVal);
        return retVal;
    }

    @Before("pe.gob.reniec.cel.aop.SystemArchitecture.servicePointcut()")
    public void beforeService() {
        logger.debug("Interceptado beforeService");
    }

    @After("pe.gob.reniec.cel.aop.SystemArchitecture.servicePointcut()")
    public void afterService() {
        logger.debug("Interceptado afterService");
    }

    @Before("pe.gob.reniec.cel.aop.SystemArchitecture.daoPointcut()")
    public void beforeDao() {
        logger.debug("Interceptado beforeDao");
    }

    @After("pe.gob.reniec.cel.aop.SystemArchitecture.daoPointcut()")
    public void afterDao() {
        logger.debug("Interceptado afterDao");
    }
}
